#!/bin/sh
# This regression test is a part of SIPp.
# -t s1 with -max_reconnect: once its UAS is gone, the UAC connects to a
# new one, and that association comes up as the first one did.
. "`dirname "$0"`/../functions"; init

"`get_sipp`" -v | grep -q SCTP || skip "no SCTP"
perl -e 'use Socket; socket(S, PF_INET, SOCK_STREAM, 132) || exit 1' ||
    skip "no SCTP sockets"

sippbg -sn uas -t s1 -i 127.0.0.1 -p 28030
uas1=$pid
# The UAC's association is up, and its first call a second away. Then
# the UAS is gone: the first call fails, and the UAC connects again, to
# the second UAS, which gets the second call.
sippfg -sn uac -t s1 -i 127.0.0.1 -p 28031 127.0.0.1:28030 \
    -m 2 -r 1 -max_reconnect 1 -reconnect_sleep 100 -timeout 6 \
    >/dev/null 2>&1 &
uac=$!
sleep 0.5
/bin/kill -9 $uas1
wait $uas1 2>/dev/null
sippfg -sn uas -t s1 -i 127.0.0.1 -p 28030 -m 1 -timeout 6 \
    >/dev/null 2>&1
status=$?
wait $uac
test $status -eq 0 || fail "the second UAS exited with $status, without its call"
ok
